Release 10.1A: OpenEdge Development:
ProDataSets
Duplicating ProDataSets with the CREATE-LIKE method
At times you need to create a new dynamic ProDataSet that has exactly the same structure as another ProDataSet, either static or dynamic. The
CREATE-LIKEmethod does this for you, much as the same method name does for temp-tables, as shown:
The important parameters are:
second-dataset-handleis the handle of a dynamic ProDataSet object with no definition, which you want to have inherit the entire definition of thefirst-dataset.prefixis an optional prefix string to be added to the beginning of the table names in thesecond-dataset. If you do not specify this, then the tables in thesecond-datasethave the same names as the tables in thefirst-dataset.To use this method, you must first create a dynamic ProDataSet, and then use
CREATE-LIKEto extract the definition of another, as in this sequence, wherehDataSetis the handle of an existing ProDataSet:
The temp-table buffers in the second ProDataSet have the same name as those in the first. Because these are dynamic temp-tables and dynamic buffers, there is no name scoping conflict with the names of the original ProDataSet. You must, in any case, reference the temp-tables and buffers in
hDataSet2by their handles in order to identify them properly. However, if you wish to have distinct table names, you must supply the optionalprefixargument.You can use
CREATE-LIKEany time you need a second dynamic ProDataSet within a procedure that has the same structure as another already defined or created. The ProDataSet structure, including temp-table and relation definitions, is copied to the second ProDataSet; the source ProDataSet’s data, however, is not copied.If you need two static ProDataSets with the same structure within a single procedure, you need to define them individually using two different names, along with temp-tables with distinct names. Unlike the dynamic temp-tables in a ProDataSet you build using
CREATE-LIKE, two static temp-tables scoped to the same procedure cannot have the same name. So, you could use a sequence of statements to create two equivalent static ProDataSets, as shown:
An include file with an argument that adds a standard prefix or suffix to the temp-table and ProDataSet names could, of course, simplify the job of defining multiple sets of temp-tables and ProDataSets with equivalent structures, like those in the preceding example.
Keep in mind that these static ProDataSets and their temp-tables must have distinct names because they are top-level, unqualified objects that share the same name space within the procedure. The Data-Relations and Relation-Fields can have the same names in both ProDataSets because they are implicitly qualified within their definitions by the ProDataSet name, just as the temp-table fields are implicitly qualified by the temp-table name. Any reference to the fields within the procedure needs to explicitly qualify the names so that Progress knows which one you’re referring to. A relation can be accessed by name through its parent ProDataSet, as in
DATASET DataSet1:GET-RELATION(“Relation1”)or inDATASET DataSet2:GET-RELATION(“Relation1”).Alternatively, you can use a persistent procedure that defines a ProDataSet as a kind of factory for multiple instances of that ProDataSet. Each running instance of the procedure has its own ProDataSet, scoped to that procedure, each with its own data.
You typically use the
CREATE-LIKEmethod to create a second ProDataSet for holding just the changes that have been made so that you can pass them to another procedure or another session for processing. This topic is discussed in later chapters along with the operation of before-tables where the original field values for changed rows are held. For now, note that if the original ProDataSet has defined before-tables, theCREATE-LIKEmethod creates a before-table for the tables in the new ProDataSet as well.For cases where you want to copy the data in one ProDataSet to another ProDataSet, you can use the
COPY-DATASETmethod, which is described in the "COPY-DATASET and COPY-TEMP-TABLE methods" section.COPY-DATASETalso lets you copy the ProDataSet structure and definition as well, if the target is a dynamic ProDataSet handle with no structure. In this way, it lets you combine what theCREATE-LIKEmethod does with copying data in the same operation.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |